<?php

class HttpTriggerConfigForm extends CFormModel {

    public $domain;

    public $portNumber;
    
    public $destinationPhoneNumber;
    
    public $timeInterval;

    /**
     * Declares the validation rules.
     */
    public function rules() {
        return array(
            array('domain, portNumber, destinationPhoneNumber, timeInterval', 'required'),
            array('domain', 'match', 'pattern' => '/^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$/'),
            array('portNumber, timeInterval', 'type', 'type' => 'number'),
            array('portNumber', 'match', 'pattern' => '/^(6553[0-5]|655[0-2]\d|65[0-4]\d\d|6[0-4]\d{3}|[1-5]\d{4}|[1-9]\d{0,3}|0)$/'),
        );
    }

    /**
     * Declares attribute labels.
     */
    public function attributeLabels() {
        return array(
            'domain' => 'Domain Name',
            'portNumber' => 'Port Number',
            'destinationPhoneNumber' => 'Destination Phone Number',
            'timeInterval' => 'Time Interval',
        );
    }

    public function store() {
        if (Yii::app()->settings->set('frontlinesms', 'domain', $this->domain) &&
                Yii::app()->settings->set('frontlinesms', 'portNumber', $this->portNumber) &&
                Yii::app()->settings->set('frontlinesms', 'destinationPhoneNumber', $this->destinationPhoneNumber) &&
                Yii::app()->settings->set('frontlinesms', 'timeInterval', $this->timeInterval)
        ) {
            return true;
        }  
        else
            return false;
    }

}
